<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>主题切换动画示例</title>
<style>
    :root {
      --bg-color: #fff;
      background-color: var(--bg-color);
    }

    :root.dark {
      --bg-color: #000;
    }

    ::view-transition-new(root),
    ::view-transition-old(root) {
      animation: none;
    }
  </style>
</head>
<body>
<button id="themeButton">切换主题</button>
<script>
    const themeButton = document.getElementById("themeButton");
    themeButton.addEventListener("click", (e) => {
      const transition = document.startViewTransition(() => {
        document.documentElement.classList.toggle("dark");
      });
      return

      transition.ready.then(() => {
        const { clientX, clientY } = e;
        const radius = Math.hypot(
          Math.max(clientX, innerWidth - clientX),
          Math.max(clientY, innerHeight - clientY)
        );

        document.documentElement.animate(
          {
            clipPath: [
              `circle(0% at ${clientX}px ${clientY}px)`,
              `circle(${radius}px at ${clientX}px ${clientY}px)`,
            ],
          },
          {
            duration: 50000,
            pseudoElement: "::view-transition-new(root)",
          }
        );
      });
    });
  </script>
</body>
</html>
